package com.bokee.archerwq.lab.file;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class FileRecordResort {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(
				"E:/jmeter/data2/calendar.csv"));
		List<String> recordList = new ArrayList<String>();
		String line = null;
		while ((line = br.readLine()) != null && line.length() > 0) {
			recordList.add(line);
		}
		br.close();

		PrintWriter pw = new PrintWriter(new FileWriter(
				"E:/jmeter/data2/calendar.csv"));
		pw.println(recordList.get(0));

		for (int i = 1; i < recordList.size(); i++) {
			String record = recordList.get(i);
			String[] items = record.split(",");
			String phoneNumber = "13800000001";
			int x = i % 4;
			if (x == 1) {
				phoneNumber = "13800000001";
			} else if (x == 2) {
				phoneNumber = "13800000002";
			} else if (x == 3) {
				phoneNumber = "13800000003";
			} else {
				phoneNumber = "13800000004";
			}

			record = items[0] + "," + items[1] + "," + items[2] + ","
					+ phoneNumber + "," + items[4] + "," + items[5];

			pw.println(record);
		}

		pw.close();
		System.out.println("done.");
	}

	public static void randSort() throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(
				"E:/jmeter/data3/calendar.csv"));
		List<String> recordList = new ArrayList<String>();
		String line = null;
		while ((line = br.readLine()) != null && line.length() > 0) {
			recordList.add(line);
		}
		br.close();

		PrintWriter pw = new PrintWriter(new FileWriter(
				"E:/jmeter/data3/calendar_new.csv"));
		pw.println(recordList.get(0));

		int count = recordList.size();
		List<Integer> indexList = new ArrayList<Integer>();
		for (int i = 1; i < count; i++) {
			indexList.add(i);
		}

		Random rand = new Random();
		while (indexList.size() > 0) {
			int j = rand.nextInt(indexList.size());
			pw.println(recordList.get(indexList.get(j)));
			indexList.remove(j);
		}
		pw.close();
	}

}
